home *** CD-ROM | disk | FTP | other *** search
/ Freelog 70 / Freelog070.iso / Internet / EasyPHP / easyphp1-8_setup.exe / {app} / phpmyadmin / lang / sync_lang.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  2004-10-13  |  7.9 KB  |  288 lines

  1. #!/bin/sh
  2. # $Id: sync_lang.sh,v 2.12 2004/10/13 08:59:36 nijel Exp $
  3. ##
  4. # Shell script that synchronises all translations in phpMyAdmin
  5. ##
  6. # Any parameters (except --iconv/--recode) will be passed to grep to filter
  7. # processed translation, for example: './sync_lang.sh czech' will process only
  8. # czech translation, './sync_lang.sh -e czech -e english' will process czech
  9. # and english translations.
  10. ##
  11. # Written by Michal Cihar <nijel at users.sourceforge.net>
  12. ##
  13. # Changes:
  14. # 2004-09-22
  15. #   * default to iconv, as it doesn't break things as recode does
  16. # 2004-09-03
  17. #   * hack for hebrew
  18. # 2003-11-18
  19. #   * switch php3 -> php
  20. # 2003-04-14
  21. #   * convert only files that are needed to convert (checks mtime), --force to
  22. #     avoid this checking
  23. #   * get charset from filename when reading from file failed
  24. #   * report failed translations at the end
  25. # 2002-09-18
  26. #   * now accepts parameters --iconv/--recode for specifying which convertor
  27. #     to use
  28. # 2002-08-13
  29. #   * support for synchronisation only for selected language(s)
  30. # 2002-07-18
  31. #   * can exclude some languages from conversion
  32. # 2002-07-17
  33. #   * support for multiple convertors (recode added)
  34. ##
  35.  
  36. ##
  37. # convertor setup
  38. ##
  39. # CONVERTOR_PARAMS is used for printf and it also receives two params: source
  40. # and target charset
  41. #
  42.  
  43. case "$1" in
  44.     --iconv)
  45.         echo Using iconv on user request
  46.         CONVERTOR=iconv
  47.         # the space on following is REQUIRED
  48.         CONVERTOR_PARAMS=" -f %s -t %s"
  49.         shift
  50.         ;;
  51.     --recode)
  52.         echo Using recode on user request
  53.         echo '(please use iconv for arabic)'
  54.         CONVERTOR=recode
  55.         CONVERTOR_PARAMS=" -f %s..%s"
  56.         shift
  57.         ;;
  58.     *)
  59.         echo Using iconv as default, force with --iconv/--recode
  60.         CONVERTOR=iconv
  61.         # the space on following is REQUIRED
  62.         CONVERTOR_PARAMS=" -f %s -t %s"
  63.         ;;
  64. esac
  65.  
  66. if [ "$1" = "--force" ] ; then
  67.     FORCE=1
  68.     shift
  69. else
  70.     FORCE=0
  71. fi
  72.  
  73.  
  74. ##
  75. # names of translations to process
  76. ##
  77. # Here should be listed all translations for which conversion should be done.
  78. # The name is filename without inc.php.
  79. #
  80. BASE_TRANSLATIONS="afrikaans-iso-8859-1
  81. albanian-iso-8859-1
  82. arabic-windows-1256
  83. azerbaijani-iso-8859-9
  84. basque-iso-8859-1
  85. bosnian-windows-1250
  86. brazilian_portuguese-iso-8859-1
  87. bulgarian-windows-1251
  88. catalan-iso-8859-1
  89. chinese_traditional-utf-8
  90. chinese_simplified-gb2312
  91. croatian-iso-8859-2
  92. czech-utf-8
  93. danish-iso-8859-1
  94. dutch-iso-8859-1
  95. english-iso-8859-1
  96. estonian-iso-8859-1
  97. finnish-iso-8859-1
  98. french-iso-8859-1
  99. galician-iso-8859-1
  100. german-utf-8
  101. greek-iso-8859-7
  102. hebrew-iso-8859-8-i
  103. hungarian-iso-8859-2
  104. indonesian-iso-8859-1
  105. italian-iso-8859-1
  106. japanese-euc
  107. korean-euc-kr
  108. latvian-windows-1257
  109. lithuanian-windows-1257
  110. malay-iso-8859-1
  111. norwegian-iso-8859-1
  112. persian-windows-1256
  113. polish-iso-8859-2
  114. portuguese-iso-8859-1
  115. romanian-iso-8859-1
  116. russian-windows-1251
  117. serbian_cyrillic-windows-1251
  118. serbian_latin-windows-1250
  119. slovenian-iso-8859-2
  120. slovak-iso-8859-2
  121. spanish-iso-8859-1
  122. swedish-iso-8859-1
  123. thai-tis-620
  124. turkish-utf-8
  125. ukrainian-windows-1251"
  126.  
  127. ##
  128. # which translations should not be translated to utf-8
  129. ##
  130. # List here any translation that should not be converted to utf-8. The name is
  131. # same as above.
  132. #
  133. IGNORE_UTF=""
  134.  
  135. ##
  136. # which translations should not be automatically generated
  137. ##
  138. # List here any translation should not be automatically generated from base
  139. # translation for that language (usually for those which are not correctly
  140. # supported by convertor).
  141. #
  142. IGNORE_TRANSLATIONS="japanese-sjis
  143. russian-cp-866"
  144.  
  145. ##
  146. # end of configuration, you hopefully won't need to edit anything bellow
  147. ##
  148.  
  149. TEMPFILE=`mktemp /tmp/pma-sync-lang.XXXXXX`
  150.  
  151. cleanup() {
  152.     rm -f $TEMPFILE
  153. }
  154.  
  155. trap cleanup INT ABRT TERM
  156.  
  157. FAILED=""
  158.  
  159. echo "-------------------------------------------------------------------"
  160. # go through all file we should process
  161. for base in $BASE_TRANSLATIONS ; do
  162.     if [ "$#" -gt 0 ] ; then
  163.         if ( echo $base | grep -q "$@" ) ; then
  164.             true
  165.         else
  166.             continue
  167.         fi
  168.     fi
  169.     # grep language from basename
  170.     lang=$(echo $base|sed 's%-.*%%')
  171.     # which files will we create from current?
  172.     create_files=$(ls --color=none -1 $lang*.inc.php|grep -v $base.inc.php)
  173.  
  174.     for ignore in $IGNORE_TRANSLATIONS ; do
  175.         create_files=$(echo "$create_files" | grep -v $ignore)
  176.     done
  177.  
  178.     # charset of source file
  179.     src_charset=$(grep '\$charset' $base.inc.php | sed "s%^[^'\"]*['\"]\\([^'\"]*\\)['\"][^'\"]*$%\\1%")
  180.     replace_charset=$src_charset
  181.     # special case for hebrew
  182.     if [ $src_charset = 'iso-8859-8-i' ] ; then
  183.         src_charset=iso-8859-8
  184.     fi
  185.     echo "$base [charset $src_charset]"
  186.  
  187.     # do we already have utf-8 translation?
  188.     if [ $src_charset = 'utf-8' ] ; then
  189.         is_utf=yes
  190.     else
  191.         is_utf=no
  192.     fi
  193.  
  194.     # at first update existing translations
  195.     for file in $create_files ; do
  196.         # charset of destination file
  197.  
  198.         # grepping from file causes problems when it is empty...
  199.         charset=$(grep '\$charset' $file | sed "s%^[^'\"]*['\"]\\([^'\"]*\\)['\"][^'\"]*$%\\1%")
  200.         if [ -z "$charset" ] ; then
  201.             charset=$(echo $file | sed -e 's/^[^-]*-//' -e 's/\.inc\.php\?$//')
  202.         fi
  203.  
  204.         if [ $charset = 'utf-8' ] ; then
  205.             is_utf=yes
  206.         fi
  207.  
  208.         # check whether we need to update translation
  209.         if [ ! "$base.inc.php" -nt "$file" -a "$FORCE" -eq 0 -a -s "$file" ] ; then
  210.             echo " $file is not needed to update"
  211.             continue
  212.         fi
  213.  
  214.         echo -n " to $charset..."
  215.         if [ $charset = 'utf-8' ] ; then
  216.             # if we convert to utf-8, we should add allow_recoding
  217.             is_utf=yes
  218.             $CONVERTOR $(printf "$CONVERTOR_PARAMS" $src_charset $charset) < $base.inc.php| sed -e "s/$replace_charset/$charset/" -e '/\$charset/a\
  219. $allow_recoding = TRUE;' > $TEMPFILE
  220.             if [ -s $TEMPFILE ] ; then
  221.                 cat $TEMPFILE > $file
  222.                 echo done
  223.             else
  224.                 FAILED="$FAILED $file"
  225.                 echo FAILED
  226.             fi
  227.         elif [ $src_charset = 'utf-8' ] ; then
  228.             is_utf=yes
  229.             # if we convert from utf-8, we should remove allow_recoding
  230.             $CONVERTOR $(printf "$CONVERTOR_PARAMS" $src_charset $charset) < $base.inc.php| grep -v allow_recoding | sed "s/$replace_charset/$charset/" > $TEMPFILE
  231.             if [ -s $TEMPFILE ] ; then
  232.                 cat $TEMPFILE > $file
  233.                 echo done
  234.             else
  235.                 FAILED="$FAILED $file"
  236.                 echo FAILED
  237.             fi
  238.         else
  239.             # just convert
  240.             $CONVERTOR $(printf "$CONVERTOR_PARAMS" $src_charset $charset) < $base.inc.php| sed "s/$replace_charset/$charset/" > $TEMPFILE
  241.             if [ -s $TEMPFILE ] ; then
  242.                 cat $TEMPFILE > $file
  243.                 echo done
  244.             else
  245.                 FAILED="$FAILED $file"
  246.                 echo FAILED
  247.             fi
  248.         fi
  249.     done
  250.  
  251.     # now check whether we found utf-8 translation
  252.     if [ $is_utf = no ] ; then
  253.         if ( echo $IGNORE_UTF | grep -q $base ) ; then
  254.             # utf-8 should not be created
  255.             true
  256.         else
  257.             # we should create utf-8 translation
  258.             echo -n " creating utf-8 translation ... "
  259.             charset=utf-8
  260.             file=$lang-$charset.inc.php
  261.             $CONVERTOR $(printf "$CONVERTOR_PARAMS" $src_charset $charset) < $base.inc.php| sed -e "s/$replace_charset/$charset/" -e '/\$charset/a\
  262. $allow_recoding = TRUE;' > $TEMPFILE
  263.             if [ -s $TEMPFILE ] ; then
  264.                 cat $TEMPFILE > $file
  265.                 echo done
  266.             else
  267.                 FAILED="$FAILED $file"
  268.                 echo FAILED
  269.             fi
  270.         fi
  271.     fi
  272.     echo "$lang processing finished."
  273.     echo "-------------------------------------------------------------------"
  274. done
  275.  
  276. if [ -z "$FAILED" ] ; then
  277.     echo "Everything seems to went okay"
  278. else
  279.     echo "!!!SOME CONVERSION FAILED!!!"
  280.     echo "Following file were NOT updated:"
  281.     echo
  282.     echo "$FAILED"
  283.     echo
  284.     echo "!!!SOME CONVERSION FAILED!!!"
  285. fi
  286.  
  287. cleanup
  288.